package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.app.Fragment;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;

/**
 * A simple {@link Fragment} subclass.
 */
    public class ShopShouCFragment extends BaseFragment {

    //获取当前屏幕的密度
    private DisplayMetrics dm;
    private Context context;
    private PagerSlidingTabStrip pagersliding;
    private ViewPager viewpager;
    private ShopShouCGoodsFragment shopShouCGoodsFragment=null;
    private ShopShouCShopFragment shopShouCShopFragment=null;
    @Override
    void initView() {
        init();

    }

    @Override
    void initEvent() {

    }

    @Override
    void initDate() {

    }


    private void init() {
        dm= getResources().getDisplayMetrics();//获取屏幕密度
        viewpager=(ViewPager)view.findViewById(R.id.viewPager);
        viewpager.setAdapter(new MyPagerAdapter(getChildFragmentManager()));
        pagersliding=(PagerSlidingTabStrip)view.findViewById(R.id.pagerslidingtabstrip);
        pagersliding.setViewPager(viewpager);
        setpagerstyle();//设置PagerSlidingTabStrip显示效果
    }
    private void setpagerstyle() {
        pagersliding.setShouldExpand(true); // 设置Tab是自动填充满屏幕的
        pagersliding.setDividerColor(Color.TRANSPARENT); // 设置Tab的分割线是透明的
// 设置Tab底部线的高度
        pagersliding.setUnderlineHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, dm));
// 设置Tab Indicator的高度
        pagersliding.setIndicatorHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 4, dm));
// 设置Tab标题文字的大小
        pagersliding.setTextSize((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_SP, 16, dm));
        pagersliding.setIndicatorColor(Color.parseColor("#45c01a"));// 设置Tab Indicator的颜色
// 设置选中Tab文字的颜色 (这是自定义的一个方法)
        pagersliding.setSelectedTextColor(Color.parseColor("#45c01a"));
        pagersliding.setTabBackground(0); // 取消点击Tab时的背景色
    }
    private class MyPagerAdapter extends FragmentPagerAdapter {
        private String[] titles = {"商店", "商品"};//显示在二级导航上的标题文字

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public android.support.v4.app.Fragment getItem(int i) {
            switch (i) {
                case 1:
                    if (shopShouCGoodsFragment == null) {
                        shopShouCGoodsFragment = new ShopShouCGoodsFragment();
                    }
                    return shopShouCGoodsFragment;
                case 0:
                    if (shopShouCShopFragment == null) {
                        shopShouCShopFragment = new ShopShouCShopFragment();
                    }
                    return shopShouCShopFragment;
                default:
                    return null;
            }
        }
    }

    public ShopShouCFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_shop_shou_c);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

}
